package com.example.wly.middletestapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    int isadd = 0;
    int add = 0;
    int result1 = 0;
    private EditText augent;
    private EditText addent;
    private TextView result;
    private Button btnadd;
    private TextView equale;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_1767111113);

        augent = (EditText) findViewById(R.id.augend);
        addent = (EditText) findViewById(R.id.augend);
        TextView plus = (TextView) findViewById(R.id.plus);
        equale = (TextView) findViewById(R.id.equal);
        btnadd = (Button) findViewById(R.id.btn_add);
        result = (TextView) findViewById(R.id.result);

        augent.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                String AugentString = augent.getText().toString();
                //判断是否为空串
                if(AugentString.equals(""))
                {
                    isadd = 0;
                }
                else
                {
                    isadd = Integer.parseInt(AugentString);//将字符串转换成整型数
                }

            }
        });

        addent.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                String AddentString = addent.getText().toString();
                //判断是否为空串
                if(AddentString.equals(""))
                {
                    add = 0;
                }
                else
                {
                    add = Integer.parseInt(AddentString);//将字符串转换成整型数
                }

            }

        });

        btnadd.setOnClickListener(new View.OnClickListener(){
            public void onClick(View v)
            {
                result1 = isadd + add;
                result.setText("" + result1);
            }
        });
    }




}
